package com.wuyi.tea.controller.common;


import com.wuyi.tea.domain.vo.R;
import com.wuyi.tea.util.LocalStorageUtil;
import com.wuyi.tea.util.MinioUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "文件上传模块")
@RestController
public class FileUploadController {

    @Resource
    private MinioUtil minioUtil;


    /**
     * 文件上传
     */
    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public R upload(MultipartFile file){
        log.info("id为{}的用户正在上传文件", LocalStorageUtil.get());
        String url = minioUtil.upload(file);
        log.info("上传成功！url: {}",url);
        return R.success("上传成功",url);
    }

}
